using System.Text;
using System.Web;

namespace eShop.Business
{
    public class SiteUtility
    {        

        public static int SuperRootCategoryId
        {
            get { return 1; }
        }

        public static int GridDefaultPageSize
        {
            get { return 20; }
        }

        public static string CleanBrandName(string rawBrandName)
        {
            StringBuilder cleanName = new StringBuilder(rawBrandName.Trim());

            for (int i = 0; i < cleanName.Length; i++)
            {
                if (!char.IsLetterOrDigit(cleanName[i]) && cleanName[i] != '-')
                {
                    cleanName[i] = '-';
                }
            }
            return cleanName.Replace("---", "-").Replace("--", "-").ToString();
        }

        public static string CleanCategoryName(string rawCategoryName)
        {
            return System.Text.RegularExpressions.Regex.Replace(rawCategoryName.ToLower(), @"[^\w\s\-]", "").Replace(" ", "-");
        }

        internal static string CleanProductName(string name)
        {
            name = System.Web.HttpUtility.HtmlDecode(name.Trim()).ToLower();
            return System.Text.RegularExpressions.Regex.Replace(name, @"[^\w\s\-]", "").Replace(" ", "-");
        }

        public static bool IsSecuredConnection
        {
            get
            {
                bool status = false;
                if (HttpContext.Current.Request.ServerVariables["HTTP_HOST"] != null)
                    status = (HttpContext.Current.Request.ServerVariables["HTTP_HOST"].ToString().ToLower() == "on");
                return status;
                //return true;
            }
        }

        public static int MaximumQuantityLength { get { return 5; } }
    }
}
